package com.lagou.edu.controller;


import com.lagou.edu.model.Article;
import com.lagou.edu.model.PageInfo;
import com.lagou.edu.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/page")
    public String listPageArticles(Model model, @RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSie) {
        PageInfo<Article> pageInfo = articleService.manualListPageArticles(pageIndex, pageSie);
        model.addAttribute("page", pageInfo);
        return "index";
    }

    @GetMapping("/auto-page")
    public String listAutoPageArticles(Model model, @RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSie) {
        PageInfo<Article> pageInfo = articleService.autoListPageArticles(pageIndex, pageSie);
        model.addAttribute("page", pageInfo);
        return "index";
    }

}
